#include <iostream>
using namespace std;

class Date
{
public:
	Date(int year = 1900, int month = 1, int day = 1)
		: _year(year)
		, _month(month)
		, _day(day)
	{}

	bool operator<(const Date& d)const
	{
		return (_year < d._year) ||
			(_year == d._year && _month < d._month) ||
			(_year == d._year && _month == d._month && _day < d._day);
	}

	bool operator>(const Date& d)const
	{
		return (_year > d._year) ||
			(_year == d._year && _month > d._month) ||
			(_year == d._year && _month == d._month && _day > d._day);
	}

	friend ostream& operator<<(ostream& _cout, const Date& d);
private:
	int _year;
	int _month;
	int _day;
};

ostream& operator<<(ostream& _cout, const Date& d)
{
	_cout << d._year << "-" << d._month << "-" << d._day;
	return _cout;
}


////普通对象大小比较没问题，指针就有问题，因此需要特化
//template<class T> 
//bool Less(T left, T right)
//{
//	return left < right;
//}

////特化,  即函数模板的专用化
//template<>
//bool Less<Date*>(Date* left, Date* right)
//{
//	return *left < *right;
//}
//

//const的函数模板专用化
template<class T>
bool Less(const T& left, const T& right) //const修饰的是left,right对象
{
	return left < right;
}

//template<>
//bool Less<Date*>(Date* const &left, Date* const &right) //const Date* 此时const修饰的是*left,*right，*之后修饰的就是left和right
//{
//	return *left < *right;
//}

//可以搭配模板一起使用
bool Less(Date* left, Date* right)
{
	return *left < *right;
}


int main()
{
	Date d1(2022, 7, 7);
	Date d2(2022, 7, 8);
	cout << Less(d1, d2) << endl;

	Date* p1 = &d1;
	Date* p2 = &d2;
	cout << Less(p1, p2) << endl;
	return 0;
}